/*
 * 严小杰创建于2023年10月
 * 用于解析机器人发过来的 KRL 程序字符串
 */

package io.github.pnoker.driver.service.netty.tcp;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class RobotXmlParser {
    public static void main(String[] args) {
        String xml = "<Robot><ID>unknown</ID><CRAF>unknown</CRAF><value>unknown</value></Robot>";

        String id = extractAttribute(xml, "ID");
        String craf = extractAttribute(xml, "CRAF");
        String value = extractAttribute(xml, "value");

    }

    public static String extractAttribute(String xml, String attributeName) {
        Document doc = Jsoup.parse(xml, "", org.jsoup.parser.Parser.xmlParser());
        Element robot = doc.select("Robot").first();
        return robot.select(attributeName).text();
    }
}



